import QtQuick 1.0

Rectangle {
    anchors.right: parent.right
    anchors.left: parent.left
    color: root.constants.activeColorAccent

    gradient: Gradient {
        GradientStop { position: 0.0; color: root.constants.activeColorAccent }
        GradientStop { position: 0.5; color: root.constants.activeColorAccent }
        GradientStop { position: 0.51; color: root.constants.activeColor }
        GradientStop { position: 1.0; color: root.constants.activeColorAccent }
    }

    Text {
        anchors.centerIn: parent
        font.pixelSize: root.constants.titleTextSize
        color: root.constants.defaultBackgroundColor
        styleColor: root.constants.transparentColor
        style: Text.Sunken
        text: "Backup2Go"
    }

    // Exit/back button
    Item {
        width: height
        height: parent.height * 0.8
        anchors.verticalCenter: parent.verticalCenter
        anchors.right: parent.right
        anchors.rightMargin: root.constants.defaultMargin

        Rectangle {
            anchors.fill: parent
            radius: width
            opacity: root.constants.shadowOpacity
            smooth: true

            gradient: Gradient {
                GradientStop { position: 0.0; color: root.constants.defaultBackgroundColor }
                GradientStop { position: 1.0; color: root.constants.defaultForegroundColor }
            }
        }

        Rectangle {
            width: parent.width * 0.8
            height: width
            anchors.centerIn: parent
            radius: width
            color: root.constants.defaultBackgroundColor
            smooth: true
        }

        Image {
            anchors.fill: parent
            scale: 1.5
            opacity: exitBackButtonMouseArea.pressed ? 1.0 : 0.0;
            source: "hilight_round.png"

            Behavior on opacity {
                NumberAnimation { duration: root.constants.veryShortAnimationDuration }
            }
        }

        Image {
            x: (viewSwitcher.currentView == fileBrowserView) ? -2 : 0;
            y: -3
            width: parent.width
            height: parent.height
            scale: 1.5
            fillMode: Image.PreserveAspectFit
            smooth: true
            z: 1
            source: (viewSwitcher.currentView == fileBrowserView) ?
                        "back_icon.png" : "close_icon.png";
        }

        MouseArea {
            id: exitBackButtonMouseArea
            anchors.fill: parent

            // Make it easy to hit
            anchors.margins: {
                top: -root.constants.defaultMargin
                bottom: -root.constants.defaultMargin
                right: -root.constants.defaultMargin
                left: -root.constants.defaultMargin
            }

            onClicked: {
                haptics.buttonTapFeedback();

                if (viewSwitcher.currentView == fileBrowserView) {
                    if (!viewSwitcher.running) {
                        viewSwitcher.switchView(mainView, true);
                    }
                }
                else {
                    // Exit the application.
                    Qt.quit();
                }
            }

            onPressedChanged: {
                if (pressed) {
                    haptics.buttonTapFeedback();
                }
            }
        }
    }
}

// End of file.
